import java.io.File;

/**
 * @author:DysonWy@Gmail.com
 * @time:2019/8/10 23:42
 */
public class RenameFile {
    static String dirPath = "I:\\动力节点\\架构师课\\vip课解压\\第一期\\SpringCloud";

    public static void main(String[] args) {
        File file = new File(dirPath);
        //判断文件存在
        if (file.exists()) {
            File[] files = file.listFiles();
            if (files == null || files.length == 0) {
                System.out.println("空文件夹");
                return;
            }
            for (File oldFile : files) {
                String oldName = oldFile.getName();
                if (oldName.contains(".ev4") && oldName.indexOf("-") == 2) {
                    String oldpath = oldFile.getPath();
                    String dirPath = oldpath.substring(0, oldpath.lastIndexOf("\\") + 1);
                    String prefix = oldName.substring(0, oldName.indexOf("-"));
                    String suffix = oldName.substring(oldName.indexOf("-") + 1);
                    String replace = suffix.replace("_", "-" + prefix + "_");
                    // System.out.println(oldName +" ==> "+dirPath+replace);
                    File newFile = new File(oldFile.getParentFile(), replace);
                    oldFile.renameTo(newFile);
                }
            }
            System.out.println("=============================");
        }
    }
}
